﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace WpfListingClientSociete
{
    /// <summary>
    /// Logique d'interaction pour MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            SingletonClients.ListeClients.ListUpdated += new Clients.UpdateHandler(ListeClients_ListUpdated);
            SingletonClients.ListeClients.ChargerClient();

        }

        void ListeClients_ListUpdated(object sender, Clients.UpdateEventArgs e)
        {
            lbClients.ItemsSource = null;
            lbClients.ItemsSource = SingletonClients.ListeClients.Tableau;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Formulaire Options = new Formulaire();
            Options.Show();
        }

        private void btnQuitter_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnSupprimer_Click(object sender, RoutedEventArgs e)
        {
            Client c = (Client)lbClients.SelectedItem;
            if (lbClients.SelectedIndex >= 0)
            {
            SingletonClients.ListeClients.SupprimerClient(c.NumClient);
            }
            else
            {
                 MessageBox.Show("Veuillez sélectionner une personne à supprimer");
            }
        }

        private void btnModifier_Click(object sender, RoutedEventArgs e)
        {

            if (lbClients.SelectedIndex >= 0)
            {
                Formulaire Options = new Formulaire(lbClients.SelectedIndex);
                Options.Show();
            }
            else 
            {
                MessageBox.Show("Veuillez sélectionner une personne à modifier");
            }
        }

    }
}
